﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 药品信息管理
{
    public partial class YF_RKDCX_MX : Form
    {
        public YF_RKDCX_MX()
        {
            InitializeComponent();
        }

        public string rkdh;

        private void buttonItem2_Click(object sender, EventArgs e)
        {
            db db1 = new db();
            db1.DataToExcel(dataGridViewX1);
        }

        private void buttonItem1_Click(object sender, EventArgs e)
        {
            dgVprint1.Print(dataGridViewX1,true);
        }

        private void YF_RKDCX_MX_Load(object sender, EventArgs e)
        {
            db db1 = new db();
            DataTable dt = db1.sqldt(@"SELECT R0.XH 序号,R0.RKDH 入库单号,convert(datetime,R0.RQ-2) 制单日期,CR.MC 入库类型,GYS.MC 供应商,
                         HJ.JJJE 进价金额,HJ.LSJE 零售金额,R0.LRRY 录入人员,R0.SHRY 审核人员,R0.SHRY 记账人员
                        FROM YK_RKD0 R0 LEFT JOIN YK_CRLX CR ON R0.RKLX = CR.BM
                                     LEFT JOIN(SELECT RKDH,SUM(JJJE) AS JJJE,SUM(LJJE) AS LSJE FROM YK_RKD1 GROUP BY RKDH) HJ ON R0.RKDH=HJ.RKDH
                                     LEFT JOIN YK_ZDGYS GYS ON R0.GYSBM=GYS.BM
                                WHERE R0.RKLX = CR.BM and R0.rkdh = " + rkdh);
            textBoxX1.Text = rkdh;
            textBoxItem1.Text = rkdh;
            try { textBoxX2.Text = dt.Rows[0]["入库类型"].ToString(); }
            catch { }
            try { textBoxX3.Text = dt.Rows[0]["录入人员"].ToString(); }
            catch { }
            try { textBoxX4.Text = dt.Rows[0]["供应商"].ToString(); }
            catch { }
            try { dateTimePicker1.Text = dt.Rows[0]["制单日期"].ToString(); }
            catch { }
            try { textBoxX5.Text = dt.Rows[0]["录入人员"].ToString(); }
            catch { }
            try { textBoxX6.Text = dt.Rows[0]["审核人员"].ToString(); }
            catch { }
            try { textBoxX7.Text = dt.Rows[0]["记账人员"].ToString(); }
            catch { }
            try { textBoxItem3.Text = dt.Rows[0]["进价金额"].ToString(); }
            catch { }
            try { textBoxItem4.Text = dt.Rows[0]["零售金额"].ToString(); }
            catch { }


            dataGridViewX1.DataSource = db1.sqldt(@"SELECT R1.YPBM 药品编码,YP.MC 药品名称,YP.GG 规格, YP.DJ 单价,YP.BZDW 包装单位,
                                                    R1.SL 入库数量,R1.JE 金额,R1.PJ 批价,R1.PJJE 批价金额,R1.FPH 发票号
                                               FROM YK_RKD1 R1 
                                                    LEFT JOIN ZD_YP YP ON R1.YPBM = YP.BM
                                              WHERE R1.RKDH=" + rkdh);
        }
    }
}